package com.pashanhoo.designpatterns.singleton;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

/**双重检查[推荐用]
 * @author 胡庆安
 * @version V1.0
 * @Package designpatterns.singleton
 * @date 2020/10/27 16:47
 * @Copyright © 2010-2020 爬山虎科技（扬州）股份有限公司
 */
@Controller
@RequestMapping("/pas")
public class DoubleCheckLazy {
    private static DoubleCheckLazy singleton;

    private DoubleCheckLazy() {}

    public static DoubleCheckLazy getInstance() {
        if (singleton == null) {
            synchronized (DoubleCheckLazy.class) {
                if (singleton == null) {
                    singleton = new DoubleCheckLazy();
                }
            }
        }
        return singleton;
    }

    @GetMapping("/getDoubleCheckLazy")
    public void getDoubleCheckLazy(){
        DoubleCheckLazy instance = getInstance();
        System.out.println(instance);
    }
}
